# docker build -t registry.lazycat.cloud/appdb/moodle:202306271 .
FROM php:8.2.7-apache-bookworm

# 加速镜像
RUN curl -sSL https://gitee.com/clh21/sh/raw/master/mirror.sh | sh

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    libzip-dev \
    libpng-dev \
    libjpeg-dev \
    libxml2-dev \
    libicu-dev \
    libfreetype6-dev \
    libldap2-dev \
    libcurl4-openssl-dev \
    libonig-dev \
    libxslt-dev \
    unzip \
    wget \
    git \
    default-mysql-client \
    && rm -rf /var/lib/apt/lists/*

# 安装 PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install gd \
    && docker-php-ext-install zip \
    && docker-php-ext-install mysqli \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install opcache \
    && docker-php-ext-install bcmath \
    && docker-php-ext-install intl \
    && docker-php-ext-install soap \
    && docker-php-ext-install xsl \
    && docker-php-ext-install ldap \
    && docker-php-ext-install curl \
    && docker-php-ext-install mbstring \
    && docker-php-ext-install sockets \
    && docker-php-ext-install gettext \
    && docker-php-ext-install exif \
    && docker-php-ext-install pcntl \
    && docker-php-ext-install shmop

RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
    && sed -i 's/.*max_input_vars.*/max_input_vars = 5000/' /usr/local/etc/php/php.ini \
    && sed -i 's/.*zend.ze1_compatibility_mode.*/zend.ze1_compatibility_mode = On/' /usr/local/etc/php/php.ini \
    && sed -i 's/.*upload_max_filesize.*/upload_max_filesize = 200M/' /usr/local/etc/php/php.ini \
    && sed -i 's/.*post_max_size.*/post_max_size = 206M/' /usr/local/etc/php/php.ini \
    && a2enmod rewrite

# moodle dir is clone from https://github.com/clh021/moodle.git
ADD moodle /var/www/html

COPY docker-entrypoint.sh /usr/local/bin/

ENV TZ UTC

ENV MOODLE_LANG=zh_cn \
  MOODLE_URL=http://localhost \
  MOODLE_DB_TYPE=mariadb \
  MOODLE_DB_HOST=db \
  MOODLE_DB_NAME=moodle \
  MOODLE_DB_USER=root \
  MOODLE_DB_PASS=password \
  MOODLE_DB_PORT=3306 \
  MOODLE_DB_PREFIX=mdl_ \
  MOODLE_FULLNAME="Study Online" \
  MOODLE_SHORTNAME="Study Online" \
  MOODLE_SUMMARY="Study Online" \
  MOODLE_ADMIN_USER=admin \
  MOODLE_ADMIN_PASS=password \
  MOODLE_ADMIN_EMAIL=moodle@heiyu.space
# Expose ports
EXPOSE 80

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

# 启动 Apache
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
